
import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.JLabel;


public class JLink extends JLabel implements MouseListener{
	private static final long serialVersionUID = 1L;

	private String destino;
	private Color colorOnFocus;
	private Color colorWithoutFocus;
	private int linkType;
	
	//tipos de link
	public static final int EMAIL = 0;
	public static final int URL = 1;
	
	//construtor
	public JLink(String destino, String exibicao, int linkType){
		this.destino = destino;
		addMouseListener(this);
		setText(exibicao);
		this.linkType = linkType;
		
		//cores padr�o
		colorOnFocus = Color.BLUE;
		colorWithoutFocus = Color.BLACK;
	}


	private void linkEmail(){
		try {
			java.awt.Desktop.getDesktop().mail( new URI("mailto:"+destino) );
		} catch (IOException e) {
			e.printStackTrace();
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}		
	}
	
	private void linkUrl(){
		try {
			java.awt.Desktop.getDesktop().browse( new URI(destino) );
		} catch (IOException e) {
			e.printStackTrace();
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}		
	}
	

	public void mouseClicked(MouseEvent arg0) {
		if (linkType == EMAIL) linkEmail();
		else if (linkType == URL) linkUrl();
	}


	public void mouseEntered(MouseEvent arg0) {
		setForeground(colorOnFocus);
		setCursor( new Cursor( Cursor.HAND_CURSOR ) );
	}


	public void mouseExited(MouseEvent arg0) {
		setForeground(colorWithoutFocus);
		setCursor( new Cursor( Cursor.DEFAULT_CURSOR ) );
	}


	public void mousePressed(MouseEvent arg0) {
		
	}


	public void mouseReleased(MouseEvent arg0) {
	
	}

	//Setters e getters
	
	public String getDestino() {
		return destino;
	}

	public void setDestino(String destino) {
		this.destino = destino;
	}

	public Color getColorOnFocus() {
		return colorOnFocus;
	}


	public void setColorOnFocus(Color colorOnFocus) {
		this.colorOnFocus = colorOnFocus;
	}


	public Color getColorWithoutFocus() {
		return colorWithoutFocus;
	}


	public void setColorWithoutFocus(Color colorWithoutFocus) {
		this.colorWithoutFocus = colorWithoutFocus;
	}

	public int getLinkType() {
		return linkType;
	}

	public void setLinkType(int linkType) {
		this.linkType = linkType;
	}
	
}

